<?php
$loader->requireOnce('includes/LabQueue/LabQueueItemModel.class.php');
$loader->requireOnce('includes/LabQueue/LabQueueAssignmentItemModel.class.php');
/**
 * Processor for lab queue model
 * @package modules.dept_laboratory.includes
 * @author viethd
 * @version $Id$
 * @copyright 2009 LHV Company
 */
class LabQueueModel {
	private $enumPatientType;
	private $queueItemsRawData;
	private $_queueItems = array();	
	function __construct($enumPatientType) {
		$this->enumPatientType = $enumPatientType;
		$labQueueObj = Celini::newOrdo('LabQueue');
        $this->queueItemsRawData = $labQueueObj->listQueueItems($enumPatientType);
		
	}
	public function buildModel() {
		//build model by status
		foreach ($this->queueItemsRawData as $row) {
			$this->addItems($row);			
		}						
	}
	/**
	 * build up or update an item in lab queue.
	 * @param $rawDataRow
	 * @return unknown_type
	 */
	private function addItems($rawDataRow) {
		if (!isset($this->_queueItems[$rawDataRow['enum_status']])) {
			$this->_queueItems[$rawDataRow['enum_status']] = array();
		}
		
		$queueItems = &$this->_queueItems[$rawDataRow['enum_status']];
		
		if (!isset($queueItems[$rawDataRow['lab_queue_id']])) {
			$queueItem = new LabQueueItemModel($rawDataRow);
			$queueItems[$rawDataRow['lab_queue_id']] = &$queueItem;						
		} else {
			$queueItem = &$queueItems[$rawDataRow['lab_queue_id']];
			$queueItem->addLabTicketItem($rawDataRow['lab_ticket_id'], $rawDataRow['lab_group_name'], $rawDataRow['is_done']);
		}
		
	} 
	/**
	 * get queue items of given status.
	 * @param $enumStatus
	 * @return array obj Of LabQueueItemModel 
	 */
	public function getQueueItems($enumStatus) {
		$status = Utils::getEnumKey(EnumerationConstant::LAB_ASSIGNMENT_TICKET_STATUS,
        $enumStatus);        
        
        if (isset($this->_queueItems[$status])) {
	        	return $this->_queueItems[$status];
	    }        
        return array();
	}

}
?>